perm filename FILEEX.SAI[LIB,AIL] blob sn#408155 filedate 1979-01-09 generic text, type T, neo UTF8
entry file!exists;
begin "file!exists"
   define library!entry = true;
   require "sys:std.hdr" source!file;
   
   internal simple boolean procedure file!exists(string filename);
   begin "file!exists"
      string dev,name,ext,ppn;
      integer sixdev, devbits, chan, dummy, flag;
      define dv!dir = ('4) lsh 18; 

      if not filescan(filename,dev,name,ext,ppn) then
         usererr(0,1,"file!exists called with syntactically bad filename");
! if the device is not a directory device then answer is no.;
      sixdev ← cvsix(dev);
      start!code
         move 1,sixdev;
         calli 1,4; ! devchr uuo;
         movem 1,devbits;
      end;
      if (dv!dir land devbits = 0) then
         return(false);

! directory device. try lookup;
      chan ← getchan;
      if chan < 0 then
         usererr(0,1,"file!exists- ran out of channels");
      open(chan,dev,0,0,0,dummy,dummy,dummy);
      lookup(chan,name&"."&ext&ppn,flag);
      release(chan);
      if flag and ((flag land '777777) = 0) then
         return(false)
      else
            return(true);
   end "file!exists";
end "file!exists";